import uuid
import time
from entity.models import db, Label
from util.LoginUtil import get_login_info


def get_label_by_label_name(label_name):
    return db.session.query(Label).filter(Label.label_name == label_name).all()


def create_new_label(label_name, create_by=""):
    label = Label()
    user_uuid = get_login_info()["user"]["uuid"]
    create_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    label_uuid = uuid.uuid4()
    label.create_at = create_date
    label.uuid = label_uuid
    label.update_at = create_date
    label.create_by = user_uuid
    label.update_by = user_uuid
    label.label_name = label_name
    db.session.add(label)
    db.session.commit()
    db.session.close()
    return label_uuid


def get_label_by_uuid(uuid):
    return db.session.query(Label).filter(Label.uuid == uuid).all()
